# 
# To change this template, choose Tools | Templates
# and open the template in the editor.
 

module PNEngine
  class Role < ActiveRecord::Base
    include Resource::InstanceMethods
    extend Resource::ClassMethods
    
    has_and_belongs_to_many :users
    
    #create a new role and set the rolename and rights
    def createRole(rolename, trInitProcess, allocate, suspend, resume, submit, delegate, review, skip)
      self.name = rolename
      self.tr_initProcess = trInitProcess
      self.allocate = allocate
      self.suspend = suspend
      self.resume = resume
      self.submit = submit
      self.delegate = delegate
      self.review = review
      self.skip = skip       
      self.save!
    end
    
    #decide whether the role has the permision to fire the transition 
    def canFireTransition(transitionAction)
      case transitionAction
        when "trInitProcess"
          return tr_initProcess
        when "allocate"
	  return allocate
	when "submit"
	  return submit
	when "suspend"
	  return suspend
	when "resume"
	  return resume
	when "delegate"
	  return delegate
	when "review"
	  return review
        when "skip"
          return skip
        else 
          return true
      end
      
    end
  end
end
